// Tableau.cpp: implementation of the CTableau class.
//
//////////////////////////////////////////////////////////////////////


#include "Tableau.h"
#include "Buffer.h"


#include "backbuffer.h"

CTableau::CTableau()
{

}

CTableau::~CTableau()
{

}

bool CTableau::CheckPushPrecondition(const CCard &_card)
{

	if( false == CSlot::CheckPushPrecondition( _card ) ) return false;


	//Get a card from the top
	if( this->cards_stored == 0 )
	{
		if( _card.IsFaceDown() )
			return true;

		if( CCard::King == _card.GetValue() ) 
			return true;
		else
			return false;
	}
	else
	{
		CCard tmp = this->PeekCard();

		if
			(	false == _card.IsFaceDown() &&
				-1 == tmp.CompareValue( _card ) &&
				( tmp.GetColor() != _card.GetColor() )
			)
			return true;
		else
			return false;
	}
}

void CTableau::OpenCard()
{
	if( this->cardstack[ cards_stored-1 ].IsFaceDown() )
		this->cardstack[ cards_stored-1 ].Flip();
}

void CTableau::Draw( unsigned int _x, unsigned int _y, bool selected )
{
    throw "Draw is not implemented yet!";
}

bool CTableau::IncreaseSelection()
{
	if( cards_stored == 0 || cards_selected == cards_stored ) return false;

	if( false == cardstack[ cards_stored - cards_selected - 1].IsFaceDown() )
	{
		cards_selected++;
		return true;
	}

	return false;

}

bool CTableau::DecreaseSelection()
{
	if( cards_stored == 0 )
	{
		cards_selected = 0;
		return false;
	}

	if( cardstack[ cards_stored - 1 ].IsFaceDown() )
	{
		cards_selected = 0;
		return false;
	}

	if( 1 == cards_selected )
		return false;

	cards_selected--;
	return true;
}


//End of file


